package com.runen.wnhz.runen.ui.fragment.major;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListView;

import com.runen.wnhz.runen.R;
import com.runen.wnhz.runen.common.utils.ACacheUtlis;
import com.runen.wnhz.runen.common.utils.ToastUtil;
import com.runen.wnhz.runen.data.entity.CatalogListEntity;
import com.runen.wnhz.runen.data.entity.LessonIntroductionEntity;
import com.runen.wnhz.runen.data.entity.TestListEntity;
import com.runen.wnhz.runen.data.entity.UserBean;
import com.runen.wnhz.runen.di.component.ApplicationComponent;
import com.runen.wnhz.runen.di.component.DaggerCourseDetailsComponent;
import com.runen.wnhz.runen.di.module.CourseDetailsModule;
import com.runen.wnhz.runen.presenter.Contart.CourseDetailsContart;
import com.runen.wnhz.runen.presenter.iPresenter.ICourseDetailsPresenter;
import com.runen.wnhz.runen.ui.adapter.puadapter.TestAdapter;
import com.runen.wnhz.runen.ui.fragment.BaseFragment;
import com.runen.wnhz.runen.widget.TitleBuilder;

import java.util.List;

import butterknife.BindView;

/**
 * Created by Administrator on 2018-04-13.
 */

public class TestFragment extends BaseFragment<ICourseDetailsPresenter> implements CourseDetailsContart.View {

    @BindView(R.id.list_catalog)
    ListView ryTest;

    private int page = 0;

    private String token;

    /**
     * Lesson_formIntroduction需要的参数
     *
     * @param lid 必填
     * @return
     */
    public static TestFragment newInstance(String lid) {
        TestFragment fragment = new TestFragment();
        Bundle bundle = new Bundle();
        bundle.putString("lid", lid);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void setupAcitivtyComponent(ApplicationComponent appComponent) {
        DaggerCourseDetailsComponent.builder().applicationComponent(appComponent)
                .courseDetailsModule(new CourseDetailsModule(this))
                .build().inject(this);
    }

    @Override
    protected int getLayoutView() {
        return R.layout.catalog_fragment_layout;
    }

    @Override
    public void initUiAndListener(View view) {

    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if(getUserVisibleHint() && getActivity() != null){
            ToastUtil.showToast("暂无内容");
        }
    }

    @Override
    protected void init() {
        super.init();
//        ryTest.setLayoutManager(new LinearLayoutManager(getActivity()));
//        ryTest.addItemDecoration(new GridSpacingItemDecoration(1,
//                DensityUtil.dp2px(10), false));
        Bundle bundle = getArguments();
        if (bundle != null) {
            ACacheUtlis cacheUtlis = ACacheUtlis.getInstance();
            if(cacheUtlis != null){
                UserBean reqeustUser = cacheUtlis.getReqeustUser(getActivity());
                if(reqeustUser != null){
                    token = reqeustUser.getToken();
                    mPresenter.getLessonTest(token,
                            bundle.getString("lid"), page + "");
                }
            }

        }
    }

    @Override
    public void initToolBar(TitleBuilder mTitleBuilder) {
        setToolBarVisible(View.GONE);
    }

    @Override
    public void showLoadding() {

    }

    @Override
    public void dimissLoding() {

    }

    @Override
    public void showErrorMessage(String msg) {

    }


    @Override
    public void onTitleButtonClicked(TitleBuilder.TitleButton clicked) {

    }

    @Override
    public void getLessonIntroRequest(LessonIntroductionEntity data) {

    }

    @Override
    public void getLessonTestRequest(TestListEntity data) {
        Log.e("===", data.getList().get(0).toString());
        TestAdapter adapter = new TestAdapter(getActivity(), data);
//        ryTest.set.setAdapter(adapter);
    }

    @Override
    public void getCatalogRequest(List<CatalogListEntity> data) {

    }
}
